﻿/**********************************************************************
File Name   : UPI_OS.h

Description : UPI OS Interface header file

Copyright (C) 2008 SMiT

Name			Version			Date			Modification
----------		-------			----------		-------------
Zheng Yang		V0.1			2008.03.03		File creation
Zhao Liang		V0.2			2008.04.03		Modify
Zhao Liang		V0.3			2008.04.16		Alpha Test
**********************************************************************/

/*! \file UPI_OS.h
 *  \brief UPI OS Interface File
 *
 *	This document defines API of OS Functions.
 *  \author Zheng Yang, Zhao Liang
 *  \version 0.3
 *  \date 2008/05/21
 */

#ifndef _UPI_OS_H
#define _UPI_OS_H
/**********************************************************************
    Includes
**********************************************************************/
//#include <sys/types.h>
//#include <sys/ipc.h>
//#include <sys/sem.h>
#include "UPI.h"

#ifdef  __cplusplus
extern "C" {
#endif


/**********************************************************************
    Constance
**********************************************************************/
/*! \def C_UPI_OS_MAX_MSG_SIZE
 * Max queue message size.
 */
#define C_UPI_OS_MAX_MSG_SIZE			(10*1024+100)
/*! \def C_UPI_OS_MAX_MSG
 * Max queue message count.
 */
#define C_UPI_OS_MAX_MSG				(8192)

/* Thread */
/*! \def C_UPI_OS_DEFAULT_STACKSIZE
 * default stack size.
 */
#define C_UPI_OS_DEFAULT_STACKSIZE		(0x20000)
/*! \def C_UPI_OS_MIN_STACKSIZE
 * Min stack size.
 */
#define C_UPI_OS_MIN_STACKSIZE			(0x20000)
/*! \def C_UPI_OS_MAX_STACKSIZE
 * Max stack size.
 */
#define C_UPI_OS_MAX_STACKSIZE			(C_UPI_OS_MIN_STACKSIZE + 0x10000)
/*! \def C_UPI_OS_MAX_THREAD_PRIORITY
 * Max thread priority.
 */
#define C_UPI_OS_MAX_THREAD_PRIORITY	(63)

/* Timer */
/*! \def C_UPI_OS_MAX_TIMER_COUNT
 * Max timer count.
 */
#define C_UPI_OS_MAX_TIMER_COUNT		(100)

/* Invalid Handle */
/*! \def C_UPI_OS_INVALID_TIMER_HANDLE
 * Invalid timer handle.
 */
#define C_UPI_OS_INVALID_TIMER_HANDLE	(0xffffffff)
/*! \def C_UPI_OS_INVALID_THREAD_HANDLE
 * Invalid thread handle.
 */
#define C_UPI_OS_INVALID_THREAD_HANDLE	((pthread_t)NULL)
/*! \def C_UPI_OS_INVALID_SEMA_HANDLE
 * Invalid semaphore handle.
 */
#define C_UPI_OS_INVALID_SEMA_HANDLE	(NULL)
/*! \def C_UPI_OS_INVALID_QUEUE_HANDLE
 * Invalid queue handle.
 */
#define C_UPI_OS_INVALID_QUEUE_HANDLE	(NULL)

/*! \enum UPI_OsThreadCreateFlag
 * Define UPI thread creation flags.
 */
typedef enum
{
    C_UPI_OS_THREAD_CREATE_DEFAULT	= 0x0,
    C_UPI_OS_THREAD_CREATE_SUSPEND	= 0x1 			/* Not Support Yet */
}UPI_OsThreadCreateFlag;

/*! \enum UPI_OsErrorCode
 * Define ErrorCode of UPI OS module.
 */
enum
{
    E_UPI_OS_TIME_SET_ERROR = E_UPI_OS_ERROR_BASE,		/*!<set os time error */
    E_UPI_OS_TIME_GET_ERROR,							/*!<get os time error */

       E_UPI_OS_TIMER_INIT_ERROR,							/*!<timer init error */
       E_UPI_OS_TIMER_CREATE_ERROR,						/*!<timer create error */
       E_UPI_OS_TIMER_START_ERROR,							/*!<timer start error */
       E_UPI_OS_TIMER_STOP_ERROR,							/*!<timer stop error */
       E_UPI_OS_TIMER_DESTROY_ERROR,						/*!<timer destroy error */
       E_UPI_OS_TIMER_SETUP_ERROR,							/*!<timer setup error */

    E_UPI_OS_THREAD_FEATURE_NOT_SUPPORT,				/*!<thread feature not support */
    E_UPI_OS_THREAD_CREATE_ERROR,						/*!<thread create error */
    E_UPI_OS_THREAD_DESTROY_ERROR,						/*!<thread destroy error */
    E_UPI_OS_THREAD_SET_PRIORITY_ERROR,					/*!<thread set priority error */
    E_UPI_OS_THREAD_GET_PRIORITY_ERROR,					/*!<thread get priority error */

    E_UPI_OS_SEMA_CREATE_ERROR,							/*!<semaphore create error */
    E_UPI_OS_SEMA_WAIT_ERROR,							/*!<semaphore wait error */
    E_UPI_OS_SEMA_TWAIT_TIMEOUT,						/*!<semaphore timed wait error */
    E_UPI_OS_SEMA_POST_ERROR,							/*!<semaphore post error */
    E_UPI_OS_SEMA_DESTROY_ERROR,						/*!<semaphore destroy error */

    E_UPI_OS_QUEUE_CREATE_ERROR,						/*!<queue create error */
    E_UPI_OS_QUEUE_SEND_ERROR,							/*!<queue send error */
    E_UPI_OS_QUEUE_FULL_ERROR,							/*!<queue is full */
    E_UPI_OS_QUEUE_RECEIVE_ERROR,						/*!<queue receive error */
    E_UPI_OS_QUEUE_TRECEIVE_TIMEOUT,					/*!<queue timed receive error */
    E_UPI_OS_QUEUE_DESTROY_ERROR,						/*!<queue destroy error */
    E_UPI_OS_QUEUE_CLEARED								/*!<queue is cleared */
};

/**********************************************************************
    Types
**********************************************************************/
/*! \struct UPI_OsTime
 * OS date and time.
 */
typedef struct _UPI_OsTime
{
    UPI_int32	Year;							/*!<Year */
    UPI_int32	Month;							/*!<Month */
    UPI_int32	Day;							/*!<Day */
    UPI_int32	Hour;							/*!<Hour */
    UPI_int32	Minute;							/*!<Minute */
    UPI_int32	Second;							/*!<Second */
    UPI_int32	WeekDay;
    UPI_int32	TimeZone;
}UPI_OsTime, *pUPI_OsTime;

/*! \struct UPI_OsSysTime
 * System time.
 */
typedef struct _UPI_OsSysTime
{
    UPI_int32	Milliseconds;					/*!<Milliseconds */
    UPI_int32	Seconds;						/*!<Seconds */
} UPI_OsSysTime, *pUPI_OsSysTime;

/*! \typedef UPI_uint32 UPI_OsPriority, *pUPI_OsPriority
 * thread priority.
 */
typedef UPI_uint32 UPI_OsPriority, *pUPI_OsPriority;

/*! \typedef pthread_t UPI_OsThreadHandle, *pUPI_OsThreadHandle
 * thread handle.
 */
typedef unsigned long UPI_OsThreadHandle, *pUPI_OsThreadHandle;

/*! \typedef UPI_int32 UPI_OsTimerHandle, *pUPI_OsTimerHandle
 * timer handle.
 */
typedef unsigned long UPI_OsTimerHandle, *pUPI_OsTimerHandle;

/*! \typedef sem_t *UPI_OsSemHandle, **pUPI_OsSemHandle
 * semaphore handle.
 */
typedef unsigned long UPI_OsSemHandle, *pUPI_OsSemHandle;

/*! \typedef void *UPI_OsQueueHandle, **pUPI_OsQueueHandle
 * queue handle.
 */
typedef unsigned long UPI_OsQueueHandle, *pUPI_OsQueueHandle;

/*! \typedef void *UPI_OsMutexHandle, **pUPI_OsMutexHandle
 * Mutex handle.
 */
typedef unsigned long UPI_OsMutexHandle, *pUPI_OsMutexHandle;
/**********************************************************************
    Function
**********************************************************************/
/*! \fn		UPI_int8 *UPI_os_get_version(void)
 *	\brief	Get UPI OS module version.
 *	\param	None
 *	\return Pointer to UPI OS version string
 */
UPI_int8 *UPI_os_get_version(void);

/*! \fn		UPI_int32 UPI_os_printf(UPI_int8 *fmt, ...)
 *	\brief	Output formatted message to serial port.
 *	\param	fmt format string
 *	\param	... data list
 *	\return Number of char outputed.
 */
UPI_int32 UPI_os_printf(UPI_int8 *fmt, ...);

/*! \fn		UPI_int32 UPI_os_warn_printf(UPI_int8 *fmt, ...)
 *	\brief	Output formatted message to serial port with yellow color.
 *	\param	fmt format string
 *	\param	... data list
 *	\return Number of char outputed.
 */
UPI_int32 UPI_os_warn_printf(UPI_int8 *fmt, ...);

/*! \fn		UPI_int32 UPI_os_error_printf(UPI_int8 *fmt, ...)
 *	\brief	Output formatted message to serial port with red color.
 *	\param	fmt format string
 *	\param	... data list
 *	\return Number of char outputed.
 */
UPI_int32 UPI_os_error_printf(UPI_int8 *fmt, ...);

/* Time Management */

/*! \fn		UPI_int32 UPI_os_set_time(pUPI_OsTime pTime)
 *	\brief	Set os time.
 *	\param	pTime pointer to UPI_OsTime struct
 *	\return E_UPI_NO_ERROR
 * 	\return E_UPI_PARAM_ERROR
 */
UPI_int32 UPI_os_set_time(pUPI_OsTime pTime);

/*! \fn		UPI_int32 UPI_os_get_time(pUPI_OsTime pTime)
 *	\brief	Get os time.
 *	\param	pTime pointer to UPI_OsTime struct
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_TIME_GET_ERROR
 */
UPI_int32 UPI_os_get_time(pUPI_OsTime pTime);

/*! \fn		UPI_int32 UPI_os_time_local2gmt(pUPI_OsTime pTime)
 *	\brief	Convert local time to GMT.
 *	\param	pTime pointer to UPI_OsTime struct
 *	\return GMT time
 * 	\return E_UPI_PARAM_ERROR
 */
UPI_uint32 UPI_os_time_local2gmt(pUPI_OsTime pTime);

/*! \fn		UPI_int32 UPI_os_time_gmt2local(UPI_int32 *pGMTTime, pUPI_OsTime pTime)
 *	\brief	Convert GMT to local time.
 *	\param	pGMTTime pointer to GMT
 *	\param	pTime pointer to UPI_OsTime struct
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_PARAM_ERROR
 */
UPI_int32 UPI_os_time_gmt2local(UPI_int32 *pGMTTime, pUPI_OsTime pTime);

/*! \fn		UPI_int32 UPI_os_current_ticktime(void)
 *	\brief	Get ticks from os run.
 *	\param	NONE
 *	\return Ticks
 */
UPI_int32 UPI_os_current_ticktime(void);

/*! \fn		UPI_int32 UPI_os_ticks_persecond(void)
 *	\brief	Get os ticks per seconf.
 *	\param	NONE
 *	\return Ticks
 */
UPI_int32 UPI_os_ticks_persecond(void);

/*	Timer Management */

/*! \fn		UPI_int32 UPI_os_timer_create(pUPI_OsTimerHandle pTimerHandle)
 *	\brief	Create a timer.
 *	\param	pTimerHandle pointer to timer handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_OS_TIMER_INIT_ERROR
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_TIMER_CREATE_ERROR
 */
UPI_int32 UPI_os_timer_create(pUPI_OsTimerHandle pTimerHandle);

/*! \fn		UPI_int32 UPI_os_timer_destroy(UPI_OsTimerHandle TimerHandle)
 *	\brief	Destroy a timer.
 *	\param	TimerHandle handle of timer
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_OS_TIMER_INIT_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_OS_TIMER_DESTROY_ERROR
 */
UPI_int32 UPI_os_timer_destroy(UPI_OsTimerHandle TimerHandle);

/*! \fn		UPI_int32 UPI_os_timer_start(UPI_OsTimerHandle TimerHandle)
 *	\brief	Start a timer.
 *	\param	TimerHandle handle of timer
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_OS_TIMER_INIT_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_OS_TIMER_START_ERROR
 */
UPI_int32 UPI_os_timer_start(UPI_OsTimerHandle TimerHandle);

/*! \fn		UPI_int32 UPI_os_timer_stop(UPI_OsTimerHandle TimerHandle)
 *	\brief	Stop a timer.
 *	\param	TimerHandle handle of timer
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_OS_TIMER_INIT_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_OS_TIMER_STOP_ERROR
 */
UPI_int32 UPI_os_timer_stop(UPI_OsTimerHandle TimerHandle);

/*! \fn		UPI_int32 UPI_os_timer_setup(UPI_OsTimerHandle TimerHandle)
 *	\brief	Setup a timer.
 *	\param	TimerHandle handle of timer
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_OS_TIMER_INIT_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_TIMER_SETUP_ERROR
 */
UPI_int32 UPI_os_timer_setup(UPI_OsTimerHandle TimerHandle,
                            void (*pTimerFunc)(void*),
                            void *pArg,
                            pUPI_OsSysTime pInitValue,
                            pUPI_OsSysTime pModulus);

/*	Thread Management */

/*! \fn		UPI_int32 UPI_os_thread_create(	void *(*pStartFunc)(void *),
                                            void *pArg,
                                            UPI_uint32 StackSize,
                                            UPI_OsPriority Priority,
                                            UPI_int8* pName,
                                            pUPI_OsThreadHandle pThreadHandle,
                                            UPI_OsThreadCreateFlag	CreateFlag)
 *	\brief	Create a thread.
 *	\param	pStartFunc		pointer to thread entry
 *	\param	pArg			pointer to startup arguments
 *	\param	StackSize		thread stack size
 *	\param	Priority		thread priority
 *	\param	pName			pointer to thread name
 *	\param	pName			pointer to thread name
 *	\param	pThreadHandle	pointer to thread handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_THREAD_FEATURE_NOT_SUPPORT
 *	\return E_UPI_OS_THREAD_CREATE_ERROR
 */
UPI_int32 UPI_os_thread_create(	void *(*pStartFunc)(void *),
                                void *pArg,
                                UPI_uint32 StackSize,
                                UPI_OsPriority Priority,
                                UPI_int8* pName,
                                pUPI_OsThreadHandle pThreadHandle,
                                UPI_OsThreadCreateFlag	CreateFlag);

/*! \fn		UPI_int32 UPI_os_thread_get_handle(pUPI_OsThreadHandle pThreadHandle)
 *	\brief	Get handle of self thread.
 *	\param	pThreadHandle	pointer to thread handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_PARAM_ERROR
 */
UPI_int32 UPI_os_thread_get_handle(pUPI_OsThreadHandle pThreadHandle);

/*! \fn		UPI_int32 UPI_os_thread_get_priority(UPI_OsThreadHandle	ThreadHandle, pUPI_OsPriority pPriority)
 *	\brief	Get pPriority of specified thread.
 *	\param	ThreadHandle	thread handle
 *	\param	pPriority		pointer to thread priority
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_THREAD_GET_PRIORITY_ERROR
 */
UPI_int32 UPI_os_thread_get_priority(UPI_OsThreadHandle	ThreadHandle, pUPI_OsPriority pPriority);

/*! \fn		UPI_int32 UPI_os_thread_set_priority(UPI_OsThreadHandle	ThreadHandle, UPI_OsPriority Priority)
 *	\brief	Get pPriority of specified thread.
 *	\param	ThreadHandle	thread handle
 *	\param	Priority		thread priority
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_THREAD_SET_PRIORITY_ERROR
 */
UPI_int32 UPI_os_thread_set_priority(UPI_OsThreadHandle	ThreadHandle, UPI_OsPriority Priority);

/*! \fn		UPI_int32 UPI_os_thread_destroy(UPI_OsThreadHandle ThreadHandle)
 *	\brief	Destroy a specified thread.
 *	\param	ThreadHandle	thread handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_OS_THREAD_DESTROY_ERROR
 */
UPI_int32 UPI_os_thread_destroy(UPI_OsThreadHandle ThreadHandle);

/*! \fn		UPI_int32 UPI_os_thread_sleep(UPI_uint32 ms)
 *	\brief	Sleep with specified time.
 *	\param	ThreadHandle	thread handle
 *	\return E_UPI_NO_ERROR
 */
UPI_int32 UPI_os_thread_sleep(UPI_uint32 ms);

/*
UPI_int32 UPI_os_thread_start(UPI_OsThreadHandle ThreadHandle);

UPI_int32 UPI_os_thread_suspend(void);

UPI_int32 UPI_os_thread_resume(UPI_OsThreadHandle ThreadHandle);
*/

/*	Semaphore Management */

/*! \fn		UPI_int32 UPI_os_semaphore_create(pUPI_OsSemHandle pSemHanle, UPI_int32 InitValue)
 *	\brief	Create a semaphore.
 *	\param	pSemHanle	pointer to semaphore handle
 *	\param	InitValue	initialized value
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_NOT_ENOUGH_MEMORY
 *	\return E_UPI_OS_SEMA_CREATE_ERROR
 */
UPI_int32 UPI_os_semaphore_create(pUPI_OsSemHandle pSemHandle, UPI_uint32 InitValue);

/*! \fn		UPI_int32 UPI_os_semaphore_destroy(pUPI_OsSemHandle pSemHandle)
 *	\brief	Destroy a semaphore.
 *	\param	pSemHandle	pointer to semaphore handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_OS_SEMA_DESTROY_ERROR
 */
UPI_int32 UPI_os_semaphore_destroy(pUPI_OsSemHandle pSemHandle);

/*! \fn		UPI_int32 UPI_os_semaphore_wait(UPI_OsSemHandle SemHandle)
 *	\brief	Wait a semaphore.
 *	\param	SemHandle	semaphore handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_OS_SEMA_WAIT_ERROR
 */
UPI_int32 UPI_os_semaphore_wait(UPI_OsSemHandle SemHandle);

/*! \fn		UPI_int32 UPI_os_semaphore_timed_wait(UPI_OsSemHandle SemHandle, UPI_int32 msTime)
 *	\brief	Wait a semaphore with timeout.
 *	\param	SemHandle	semaphore handle
 *	\param	msTime		timeout time
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_SEMA_TWAIT_TIMEOUT
 */
UPI_int32 UPI_os_semaphore_timed_wait(UPI_OsSemHandle SemHandle, UPI_uint32 msTime);

/*! \fn		UPI_int32 UPI_os_semaphore_post(UPI_OsSemHandle SemHandle)
 *	\brief	Post a semaphore.
 *	\param	SemHandle	semaphore handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_OS_SEMA_POST_ERROR
 */
UPI_int32 UPI_os_semaphore_post(UPI_OsSemHandle SemHandle);

/*	Queue Management */

/*! \fn		UPI_int32 UPI_os_queue_create(	pUPI_OsQueueHandle pQueueHandle,
                                UPI_uint32 MaxMessage,
                                UPI_uint32 MaxMessageSize)
 *	\brief	Create a queue.
 *	\param	pQueueHandle	pointer to queue handle
 *	\param	MaxMessage		max message count the queue can hold
 *	\param	MaxMessageSize	max message size the queue can hold
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_NOT_ENOUGH_MEMORY
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_QUEUE_CREATE_ERROR
 */
UPI_int32 UPI_os_queue_create(	pUPI_OsQueueHandle pQueueHandle,
                                UPI_uint32 MaxMessage,
                                UPI_uint32 MaxMessageSize);

/*! \fn		UPI_int32 UPI_os_queue_destroy(UPI_OsQueueHandle QueueHandle)
 *	\brief	Destroy a queue.
 *	\param	QueueHandle		queue handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 * 	\return E_UPI_UNKNOWN_ERROR
 */
UPI_int32 UPI_os_queue_destroy(UPI_OsQueueHandle QueueHandle);

/*! \fn		UPI_int32 UPI_os_queue_send(UPI_OsQueueHandle QueueHandle,
                                        void* pBuffer,
                                        UPI_uint32 BufferSize);
 *	\brief	sen message to queue, first in first out.
 *	\param	QueueHandle		queue handle
 *	\param	pBuffer			pointer to message buffer
 *	\param	BufferSize		message size
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_QUEUE_SEND_ERROR
 *	\return E_UPI_OS_QUEUE_FULL_ERROR
 */
UPI_int32 UPI_os_queue_send(UPI_OsQueueHandle QueueHandle,
                            void* pBuffer,
                            UPI_uint32 BufferSize);

/*! \fn		UPI_int32 UPI_os_queue_send_lifo(UPI_OsQueueHandle QueueHandle,
                                            void* pBuffer,
                                            UPI_uint32 BufferSize);
 *	\brief	sen message to queue, last in first out.
 *	\param	QueueHandle		queue handle
 *	\param	pBuffer			pointer to message buffer
 *	\param	BufferSize		message size
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_QUEUE_SEND_ERROR
 *	\return E_UPI_OS_QUEUE_FULL_ERROR
 */
UPI_int32 UPI_os_queue_send_lifo(UPI_OsQueueHandle QueueHandle,
                                void* pBuffer,
                                UPI_uint32 BufferSize);

/*! \fn		UPI_int32 UPI_os_queue_receive(	UPI_OsQueueHandle QueueHandle,
                                            void* pBuffer,
                                            UPI_uint32 BufferSize,
                                            UPI_int32 *pCount )
 *	\brief	Receive message from a queue.
 *	\param	QueueHandle		queue handle
 *	\param	pBuffer			pointer to buffer to receive message
 *	\param	BufferSize		Buffer size
 *	\param	pCount			pointer to Count
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_QUEUE_RECEIVE_ERROR
 */
UPI_int32 UPI_os_queue_receive(	UPI_OsQueueHandle QueueHandle,
                                void* pBuffer,
                                UPI_uint32 BufferSize,
                                UPI_int32 *pCount );

/*! \fn		UPI_int32 UPI_os_queue_timed_receive(	UPI_OsQueueHandle QueueHandle,
                                                    void* pBuffer,
                                                    UPI_uint32 BufferSize,
                                                    UPI_int32 *pCount,
                                                    UPI_int32 msTime)
 *	\brief	Receive message from a queue with timeout.
 *	\param	QueueHandle		queue handle
 *	\param	pBuffer			pointer to buffer to receive message
 *	\param	BufferSize		Buffer size
 *	\param	pCount			pointer to Count
 *	\param	msTime			timeout time
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_INVALID_HANDLE
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_OS_QUEUE_RECEIVE_ERROR
 *	\return E_UPI_OS_QUEUE_TRECEIVE_TIMEOUT
 */
UPI_int32 UPI_os_queue_timed_receive(	UPI_OsQueueHandle QueueHandle,
                                        void* pBuffer,
                                        UPI_uint32 BufferSize,
                                        UPI_int32 *pCount,
                                        UPI_uint32 msTime);


/*	Mutex Management */

/*! \fn		UPI_int32 UPI_os_mutex_create(pUPI_OsMutexHandle pMutexHandle)
 *	\brief	Create a mutex.
 *	\param	pMutexHandle	pointer to mutex handle
 *	\param	InitValue	initialized value
 *	\return E_UPI_NO_ERROR
 * 	\return E_UPI_FALSE
 *	\return E_UPI_PARAM_ERROR
 *	\return E_UPI_NOT_ENOUGH_MEMORY
 */
UPI_int32 UPI_os_mutex_create(pUPI_OsMutexHandle pMutexHandle);

/*! \fn		UPI_int32 UPI_os_mutex_destroy(UPI_OsMutexHandle MutexHandle)
 *	\brief	Destory a mutex.
 *	\param	MutexHandle	 mutex handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_FALSE
 *	\return E_UPI_INVALID_HANDLE
 */
UPI_int32 UPI_os_mutex_destroy(UPI_OsMutexHandle MutexHandle);

/*! \fn		UPI_int32 UPI_os_mutex_lock(UPI_OsMutexHandle MutexHandle)
 *	\brief	Lock a mutex.
 *	\param	MutexHandle	 mutex handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_FALSE
 *	\return E_UPI_INVALID_HANDLE
 */
UPI_int32 UPI_os_mutex_lock(UPI_OsMutexHandle MutexHandle);

/*! \fn		UPI_int32 UPI_os_mutex_unlock(UPI_OsMutexHandle MutexHandle)
 *	\brief	Unlock a mutex.
 *	\param	MutexHandle	 mutex handle
 *	\return E_UPI_NO_ERROR
 *	\return E_UPI_FALSE
 *	\return E_UPI_INVALID_HANDLE
 */
UPI_int32 UPI_os_mutex_unlock(UPI_OsMutexHandle MutexHandle);

/*	Memory Management */

/*! \fn		void *UPI_os_malloc(UPI_uint32 Size)
 *	\brief	Allocate memory.
 *	\param	Size		required size
 *	\return pointer to allocated memory
 */
void *UPI_os_malloc(UPI_uint32 Size);

/*! \def UPI_os_free
 * free memory space and set pointer to NULL.
 */
#define UPI_os_free(pBuffer)	{_UPI_os_free(pBuffer);pBuffer = NULL;}

/*! \fn		void UPI_os_mul_u32(UPI_s64 *Result, UPI_s64 *Value1, UPI_uint32 Value2)
 *	\brief	64 bit mul operator R=(V1*V2).
 *	\param	Result		output multiplication result
 *	\param	Value1		input, multiplication parameter1
 *	\param	Value2		input, multiplication parameter2
 *	\return pointer to allocated memory
 */
//void UPI_os_s64_mul_u32(UPI_s64 *Result, UPI_s64 *Value1, UPI_uint32 Value2);
#ifdef  __cplusplus
}
#endif

#endif /* _UPI_OS_H */
